<template>
    <div>
        <h2>会员添加</h2>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>会员编号</td>
                    <td>
                        <input type="text" v-model="model.UserCode">
                    </td>
                </tr>


                <tr>
                    <td>会员名称</td>
                    <td>
                        <input type="text" v-model="model.UserName">
                    </td>
                </tr>


                <tr>
                    <td>会员手机号</td>
                    <td>
                        <input type="text" maxlength="11" v-model="model.Phone">
                    </td>
                </tr>

                <tr>
                    <td>身份证号</td>
                    <td>
                        <input type="text" maxlength="18"  v-model="model.Code">
                    </td>
                </tr>




                <tr>
                    <td>性别</td>
                    <td>
                        <input type="radio" name="sex" :value="1" v-model="model.Sex"> 男
                        <input type="radio" name="sex" :value="0" v-model="model.Sex"> 女
                    </td>
                </tr>

                


                <tr>
                    <td>状态</td>
                    <td>
                        <input type="radio" name="state" :value="1"  v-model="model.State"> 启用
                        <input type="radio" name="state" :value="0"  v-model="model.State"> 禁用
                    </td>
                </tr>



                <tr>
                    <td>会员积分</td>
                    <td>
                        <input type="text" v-model="model.JiFen">
                    </td>
                </tr>


                <tr>
                    <td>会员余额</td>
                    <td>
                        <input type="text" v-model="model.Money">
                    </td>
                </tr>

                <tr>
                    <td>会员等级</td>
                    <td>
                       <select v-model="model.LevelId">
                            <option :value="-1">请选择</option>
                         <option v-for="item in list" :key="item.Id" :value="item.Id" > {{item.LevelName}}</option>
                       </select>
                    </td>
                </tr>


                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="添加" class="btn btn-success"  @click="ok">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import axios from 'axios';
const route = useRoute();
const router = useRouter();

let model = reactive({

  "UserCode": '',
  "UserName": '',
  "Phone": '',
  "Code": '',
  "Sex": 1,
  "State": 1,
  "JiFen": '',
  "Money": '',
  "LevelId": -1,
 
})



//添加
const ok = () => {
   
    axios({
        url:'https://localhost:7035/api/ZUser/UserAdd',
        method: 'post',
        data: model,
    })

        .then((res) => {
            console.log(res);
            if (res.data == -1) {
                alert('身份证号已重复');
                return;
            }
            else if (res.data == 1) {
                alert('添加成功');
                router.push('/userlist')
                return;
            }
            else {
                alert('添加失败');

                return;

            }
        })


        .catch((ree) => {
            console.log(ree);
        })

}



//查询
let obj = reactive({
    LevelName: '',
})

//数据
const list: any = ref([]);


//显示
onMounted(() => {
GetLevelList();
})


//发送后台
const GetLevelList = () => {

    axios({
        url: 'https://localhost:7035/api/ZMemberLevel/ZMemberLevelList',
        method: 'get',
        params: model,
    })

        .then((res) => {
            console.log(res);
            list.value = res.data;
        })


        .catch((ree) => {
            console.log(ree);
        })

}
</script>

<style scoped></style>